package com.yuncheng.spcyApi.spcy;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.entity.SpcyJcyFybxd;
import com.yuncheng.spcyApi.entity.SpcyJcyFybxdgrjl;
import com.yuncheng.spcyApi.entity.SpcyJcyFybxdtssxsq;
import com.yuncheng.entity.YcSysUser;
import com.yuncheng.spcyApi.spcyService.JcyFybxdService;
import com.yuncheng.spcyApi.vo.common.HttpResultVo;
import com.yuncheng.spcyApi.vo.common.OrderItemVo;
import com.yuncheng.spcyApi.vo.common.PageVo;
import com.yuncheng.spcyApi.vo.sqsx.AddJcyBxryInfoVo;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hua
 */
@Api(tags = "检查员费用报销单管理")
@RestController
@RequestMapping("/api/spzx-spcy/jcyfybxd")
public class JcyFybxdController {

    @Resource
    private JcyFybxdService jcyFybxdService;

    @Log(title = "查询费用报销单-分页列表")
    @ApiOperation(value = "查询费用报销单-分页列表")
    @GetMapping(value = "queryFybxdPageList")
    public HttpResult queryFybxdPageList(SpcyJcyFybxd fybxd, String gjz, PageVo pageVo, OrderItemVo orderItemVo){
        return jcyFybxdService.queryFybxdPageList(fybxd, gjz, false, pageVo, orderItemVo);
    }

    /*@Log(title = "查询我的费用报销单-分页列表")
    @ApiOperation(value = "查询我的费用报销单-分页列表")*/
    @GetMapping(value = "queryMyFybxdPageList")
    public HttpResult queryMyFybxdPageList(SpcyJcyFybxd fybxd, String gjz, PageVo pageVo, OrderItemVo orderItemVo){
        return jcyFybxdService.queryFybxdPageList(fybxd, gjz, true, pageVo, orderItemVo);
    }

    /*@Log(title = "初始化申请事项-费用报销单")
    @ApiOperation(value = "初始化申请事项-费用报销单")*/
    @GetMapping(value = "initSqsxFybxd")
    public HttpResult initSqsxFybxd(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){
        jcyFybxdService.initSqsxFybxd(sqsxid);

        return HttpResult.ok();
    }

    /*@Log(title = "查询报销单列表-根据sqsxid")
    @ApiOperation(value = "查询报销单列表-根据sqsxid")*/
    @GetMapping(value = "queryBxdListBySqsxId")
    public HttpResult queryBxdListBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

        List<SpcyJcyFybxd> list = jcyFybxdService.queryBxdListBySqsxId(sqsxid);

        return HttpResultVo.HttpResultList(list);
    }


    @Log(title = "查询报销人员信息列表-根据sqsxid")
    @ApiOperation(value = "查询报销人员信息列表-根据sqsxid")
    @GetMapping(value = "queryBxryxxListBySqsxId")
    public HttpResult queryBxryxxListBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){


        return HttpResult.ok(jcyFybxdService.queryBxryxxListBySqsxId(sqsxid));
    }

    @Log(title = "查询报销人员记录列表-根据申请事项id")
    @ApiOperation(value = "查询报销人员记录列表-根据申请事项id")
    @GetMapping(value = "queryBxryjlBySqsxId")
    public HttpResult queryBxryjlBySqsxId(@RequestParam(value = "sqsxid",defaultValue = "SQSXID")String sqsxid){


//        return HttpResultVo.HttpResultList(jcyFybxdService.queryBxryjlBySqsxId(sqsxid));
        return HttpResultVo.HttpResultList(jcyFybxdService.queryHydjryBySqsxId(sqsxid));
    }

    /*@Log(title = "删除费用报销单及明细")
    @ApiOperation(value = "删除费用报销单及明细")*/
    @GetMapping(value = "deleteFybxdAndRymx")
    public HttpResult deleteFybxdAndRymx(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        jcyFybxdService.deleteFybxdAndRymx(fbxdid);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "查询专家劳务费列表-根据报销单id")
    @ApiOperation(value = "查询专家劳务费列表-根据报销单id")
    @GetMapping(value = "queryZjlwfList")
    public HttpResult queryZjlwfList(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        List<SpcyJcyFybxdgrjl> list = jcyFybxdService.queryZjlwfList(fbxdid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "查询报销人员信息列表-根据报销单id")
    @ApiOperation(value = "查询报销人员信息列表-根据报销单id")
    @GetMapping(value = "queryBxryxxListByBxdId")
    public HttpResult queryBxryxxListByBxdId(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        List<SpcyJcyFybxdgrjl> list = jcyFybxdService.queryBxryxxListByBxdId(fbxdid);

        return HttpResultVo.HttpResultList(list);
    }

    @Log(title = "查询报销单信息-根据报销单id")
    @ApiOperation(value = "查询报销单信息-根据报销单id")
    @GetMapping(value = "queryBxdById")
    public HttpResult queryBxdById(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){
        return HttpResult.ok(jcyFybxdService.queryBxdById(fbxdid));
    }

    @Log(title = "查询报销单及人员明细-根据报销单id")
    @ApiOperation(value = "查询报销单及人员明细-根据报销单id")
    @GetMapping(value = "queryBxdMxById")
    public HttpResult queryBxdMxById(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){
        Map resultMap = new HashMap();
        SpcyJcyFybxd fybxd = jcyFybxdService.queryBxdById(fbxdid);
        List<SpcyJcyFybxdgrjl> bxmxList = jcyFybxdService.queryBxryxxListByBxdId(fbxdid);

        resultMap.put("bxd", fybxd);
        resultMap.put("bxmxList", bxmxList);
        return HttpResult.ok(resultMap);
    }

    @Log(title = "查询可选择人员-分页列表")
    @ApiOperation(value = "查询可选择人员-分页列表")
    @GetMapping(value = "queryKSelectUserPageList")
    public HttpResult queryKSelectUserPageList(YcSysUser query, String gjz, PageVo pageVo){
        return jcyFybxdService.queryKSelectUserPageList(query, gjz, pageVo);
    }

    @Log(title = "新增会议登记人员用户信息")
    @ApiOperation(value = "新增会议登记人员用户信息")
    @PostMapping(value = "addBxryUserInfo")
    public HttpResult addBxryUserInfo(@RequestBody AddJcyBxryInfoVo jcyBxryInfoVo) throws InvocationTargetException, IllegalAccessException {

//        return jcyFybxdService.addBxryUserInfo(jcyBxryInfoVo);
        return jcyFybxdService.addHydjryUserInfo(jcyBxryInfoVo);
    }

    @Log(title = "保存选择会议-会议登记人员")
    @ApiOperation(value = "保存选择会议-会议登记人员")
    @GetMapping(value = "saveSelectBxry")
    public HttpResult saveSelectBxry(@RequestParam(value = "ids",defaultValue = "")String ids,
                                     @RequestParam(value = "fbxdid",defaultValue = "")String fbxdid,
                                     @RequestParam(value = "fjcsf",defaultValue = "")String fjcsf,
                                     @RequestParam(value = "sqsxid",defaultValue = "")String sqsxid){

//       return jcyFybxdService.saveSelectBxry(ids, fbxdid, sqsxid, fjcsf);
       return jcyFybxdService.saveSelectHydjry(ids, fbxdid, sqsxid, fjcsf);
    }

    @Log(title = "删除报销人员明细-根据报销人员id")
    @ApiOperation(value = "删除报销人员明细-根据报销人员id")
    @DeleteMapping(value = "deleteBxrymxById")
    public HttpResult deleteBxrymxById(@RequestParam(value = "id",defaultValue = "")String id){

//        jcyFybxdService.deleteBxrymxById(id);
        jcyFybxdService.deleteHydjryById(id);

        return HttpResult.ok("删除成功");
    }

    @Log(title = "更新报销单信息")
    @ApiOperation(value = "更新报销单信息")
    @PostMapping(value = "updateBxd")
    public HttpResult updateBxd(@RequestBody HashMap<String,String> buffer) throws IllegalAccessException, InvocationTargetException {

        jcyFybxdService.updateBxd(buffer);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "更新报销人员明细信息")
    @ApiOperation(value = "更新报销人员明细信息")
    @PostMapping(value = "updateBxrymxxx")
    public HttpResult updateBxrymxxx(@RequestBody HashMap<String,String> buffer) throws IllegalAccessException, InvocationTargetException {

//        jcyFybxdService.updateBxrymxxx(buffer);
        jcyFybxdService.updateHydjrymxxx(buffer);

        return HttpResult.ok("保存成功");
    }

    @PostMapping(value = "updateBxmx")
    public HttpResult updateBxmx(@RequestBody HashMap<String,String> buffer) throws IllegalAccessException, InvocationTargetException {

        jcyFybxdService.updateBxrymxxx(buffer);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "查询当前记录的对应垫付人员列表")
    @ApiOperation(value = "查询当前记录的对应垫付人员列表")
    @GetMapping(value = "queryFybxdDfryList")
    public HttpResult queryFybxdDfryList(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid,
                                         @RequestParam(value = "id",defaultValue = "")String id){

        if (StringUtils.isBlank(fbxdid)){
            return HttpResult.error("参数为空！");
        }
        if (StringUtils.isBlank(id)){
            id = "135qr";
        }
        List<Map> mapList = jcyFybxdService.queryFybxdDfryList(fbxdid, id);

        return HttpResult.ok(mapList);
    }

    @Log(title = "查询申请人员列表")
    @ApiOperation(value = "查询申请人员列表")
    @GetMapping(value = "queryFybxdSqryList")
    public HttpResult queryFybxdSqryList(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        if (StringUtils.isBlank(fbxdid)){
            return HttpResult.error("参数为空！");
        }
        List<Map> mapList = jcyFybxdService.queryFybxdDfryList(fbxdid, null);

        return HttpResultVo.HttpResultList(mapList);
    }

    @Log(title = "报销单信息-下一步")
    @ApiOperation(value = "报销单信息-下一步")
    @GetMapping(value = "submitFybxd")
    public HttpResult submitFybxd(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        return jcyFybxdService.submitFybxd(fbxdid);
    }

    @Log(title = "报销单信息-上一步")
    @ApiOperation(value = "报销单信息-上一步")
    @GetMapping(value = "returnFybxd")
    public HttpResult returnFybxd(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid){

        return jcyFybxdService.returnFybxd(fbxdid);
    }

    @Log(title = "批量设置出行方式")
    @ApiOperation(value = "批量设置出行方式")
    @GetMapping(value = "batchSetBxdCxfs")
    public HttpResult batchSetBxdCxfs(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid,
                                      @RequestParam(value = "fcsjjtfs",defaultValue = "")String fcsjjtfs){

        jcyFybxdService.batchSetBxdCxfsByBxdId(fbxdid, fcsjjtfs);

        return HttpResult.ok("设置成功");
    }

    /** 2024-02-26 新增*/
    @Log(title = "批量设置劳务费/伙食/交通补助天数")
    @ApiOperation(value = "批量设置劳务费/伙食/交通补助天数")
    @GetMapping(value = "batchSzLwHsJtbzTs")
    public HttpResult batchSzLwHsJtbzTs(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid,
                                        @RequestParam(value = "fjcts",defaultValue = "")String fjcts){
        jcyFybxdService.batchSzLwHsJtbzTs(fbxdid, fjcts);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "特殊事项申请-分页查询")
    @ApiOperation(value = "特殊事项申请-分页查询")
    @GetMapping(value = "queryFybxdTssxSqPageList")
    public HttpResult queryFybxdTssxSqPageList(@RequestParam(value = "fbxdid",defaultValue = "")String fbxdid,
                                               PageVo pageVo){

        return jcyFybxdService.queryFybxdTssxSqPageList(fbxdid, pageVo);
    }

    @Log(title = "特殊事项申请-根据id查看")
    @ApiOperation(value = "特殊事项申请-根据id查看")
    @GetMapping(value = "queryFybxdTssxSqById")
    public HttpResult queryFybxdTssxSqById(@RequestParam(value = "id",defaultValue = "")String id){

        return HttpResult.ok(jcyFybxdService.queryFybxdTssxSqById(id));
    }

    @Log(title = "特殊事项申请-新增")
    @ApiOperation(value = "特殊事项申请-新增")
    @PostMapping(value = "addFybxdTssxSq")
    public HttpResult addFybxdTssxSq(@RequestBody SpcyJcyFybxdtssxsq bean){

        return HttpResultVo.HttpResultSave(jcyFybxdService.addFybxdTssxSq(bean), "添加成功");
    }

    @Log(title = "特殊事项申请-更新")
    @ApiOperation(value = "特殊事项申请-更新")
    @PutMapping(value = "updateFybxdTssxSq")
    public HttpResult updateFybxdTssxSq(@RequestBody HashMap<String,String> buffer) throws InvocationTargetException, IllegalAccessException {
        jcyFybxdService.updateFybxdTssxSq(buffer);

        return HttpResult.ok("保存成功");
    }

    @Log(title = "特殊事项申请-删除")
    @ApiOperation(value = "特殊事项申请-删除")
    @GetMapping(value = "deleteFybxdTssxSq")
    public HttpResult deleteFybxdTssxSq(@RequestParam(value = "id",defaultValue = "")String id){
        jcyFybxdService.deleteFybxdTssxSq(id);

        return HttpResult.ok("删除成功");
    }


}
